package storage.buffer;

import java.nio.ByteBuffer;
import java.util.*;

import storage.file.*;

public abstract class AbstractBufferManager {
	protected static String identifier = AbstractBufferManager.class.getCanonicalName();
	
	protected Hashtable<BlockID, Block> bufferPool = new Hashtable<BlockID, Block>();
	protected int BUFFER_SIZE = 4096;
	protected int size = 0;
	
	public abstract Block allocatePage(BlockID pageID);
	public abstract void deallocatePage(BlockID pageID);
	public abstract void pinPage(BlockID pageID);
	public abstract void unpinPage(BlockID pageID);
	public abstract boolean writePage(BlockID pageID, ByteBuffer data);
	public abstract boolean readPage(BlockID pageID, ByteBuffer data);
	public abstract boolean flushAll();
	
	synchronized public Block allocateAndPinPage(BlockID pageID) {
		Block page = allocatePage(pageID);
		pinPage(pageID);
		return page;
	}
	
	public Collection<BlockID> getBufferedPages() {
		return bufferPool.keySet();
	}
}